package com.ziguang.redwood.admin.controller;


import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.ext.route.ControllerBind;
import com.ziguang.redwood.admin.validator.LoginValidator;
import com.ziguang.common.SysConstant;
import com.ziguang.common.interceptor.AuthInterceptor;
import com.ziguang.redwood.admin.service.LoginService;


@ControllerBind(controllerKey = "/managerlogin", viewPath = "/admin")
public class LoginController extends Controller {
	
	public void index(){
		render("login.html");
	}
	
	
	@Before(LoginValidator.class)
	public void login() {
		
		// 接收参数
		String userName = getPara("txt_user");
		String userPwd = getPara("txt_pwd");
		// 验证
		if (LoginService.me.query(userName, userPwd) == 1) {
			setSessionAttr(SysConstant.SESSION_INFO, userName);
			redirect("/indexMenu");
		} else {
			setAttr("Code", "E001");
			removeSessionAttr(SysConstant.SESSION_INFO);
			render("login.html");
		}
	}
}
